﻿//     Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Threading.Tasks;

namespace Gateway.Console.Models
{
    public static class StatusExtensions
    {
        public static async Task AddStatusAsync<TStatus>(this ConsoleContext db, int parentId, DateTime date, bool success, string message) 
            where TStatus : Status, new()
        {
            TStatus newStatus = new TStatus
            {
                DateAdded = date,
                Success = success,
                Message = message,
            };
            newStatus.SetParentId(parentId);
            db.Set<TStatus>().Add(newStatus);
            await db.SaveChangesAsync();
        }

        public static void AddStatus<TStatus>(this ConsoleContext db, int parentId, DateTime date, bool success, string message) 
            where TStatus : Status, new()
        {
            db.AddStatusAsync<TStatus>(parentId, date, success, message).Wait();
        }

    }
}